﻿/*********************弘石项目三组************************
*  功能描述：系统设置-人员设置
*  作者：黄启轩
*  时间：2020-12-08
*  修改人：黄启轩
*  修改时间：2020-12-08
*********************弘石项目三组************************/
using Hong.Business.Business_SystemSettings;
using Hong.Model.SysDomain.Model_SystemSettings;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.IO;
using System.Threading.Tasks;

namespace WeHongshibApI.Controllers.Controllers_SystemSettings
{
    [ApiExplorerSettings(GroupName = "SystemSettings")]
    [Route("api/[controller]")]
    [ApiController]
    public class PersonnelController : ControllerBase
    {
        #region 构造器API注入
        private readonly PersonnelBll _PersonnelBll;
        public PersonnelController(PersonnelBll PersonnelBll)
        {
            _PersonnelBll = PersonnelBll;
        }

        #endregion

        #region 人员管理

        #region 人员显示
       

        #endregion

        #region 人员添加
        [HttpPost,Route("AddPer")]
        public async Task<IActionResult> AddPer(Personnel personnel)
        { 
            var result=await _PersonnelBll.AddPer(personnel);
            return Ok(result);
        }
        #endregion

        #region 加载人员
        [HttpGet,Route("GetPer")]
        public async Task<IActionResult> GetPer(int? depId, string PersonnelName, int pageindex, int pagesize)
        {
            var result = await _PersonnelBll.GetPer(depId, PersonnelName, pageindex, pagesize);
            return Ok(result);
        }
        #endregion

        #region 删除人员
        [HttpPost, Route("DelPer")]
        public async Task<IActionResult> DelPer(Guid PersonnelId)
        { 
            var result=await _PersonnelBll.DelPer(PersonnelId);
            return Ok(result);
        }
        #endregion

        #region 上传头像
        [HttpPost,Route("UpLoad")]
        public IActionResult UpLoad()
        {
            //tp 协议 Request Response
             //获取文件
             var hpf = Request.Form.Files[0];
            //新名称
            var newFileName = Guid.NewGuid().ToString();
            //获取扩展名
            var ext = Path.GetExtension(hpf.FileName);
            //将文件名和扩展名拼接
            var newName = newFileName + ext;
            //找到路径  将虚拟路径转成物理路径
            var path = Directory.GetCurrentDirectory() + "/Images";
            //合并路径和文件名
            var newPath = Path.Combine(path, newName);

            using (var stream = System.IO.File.Create(newPath))
            {
                hpf.CopyTo(stream);

            }
            return Ok(new { url = "https://localhost:44393/StaticFiles/" + newName });
        }
        #endregion


        #endregion
    }
}
